package com.neusoft.neuiotms.dcam.fixed.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@Table(name = "neuiot_contract")
@org.hibernate.annotations.Table(appliesTo = "neuiot_contract", comment = "合同表")
public class Contract extends AbstractAuditModel {

    private static final long serialVersionUID = 1L;

    /** 合同名 */
    @NotBlank(message = "合同名不能为空")
    @Length(max = 255, message = "合同名不能超过{max}位")
    @Comment("varchar(255) NOT NULL COMMENT '合同名称'")
    private String name;

    /** 合同号 */
    @Length(max = 255, message = "合同号不能超过{max}位")
    @Column(length = 255, nullable = true)
    private String code;

    /** 邮编 */
    @Length(max = 255, message = "邮编不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '邮编'")
    private String postCode;

    /** 签订日期 */
    @Column(nullable = true)
    @Comment("datetime NULL COMMENT '签订日期'")
    private Date signingDate;

    /** 质量保障 */
    @Length(max = 255, message = "质量保障不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '质量保障'")
    private String qualityAssurance;

    /** 交货期限 */
    @Column(length = 11, nullable = true)
    private Integer deliveryDeadline = 1;

    /** 运输方式 */
    @Length(max = 255, message = "运输方式不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '运输方式'")
    private String transport;

    /** 包装方式 */
    @Length(max = 255, message = "包装方式不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '包装方式'")
    private String packing;

    /** 到货地点 */
    @Length(max = 255, message = "到货地点不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '到货地点'")
    private String arrivalAddress;

    /** 付款条件 */
    @Length(max = 255, message = "付款条件不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '付款条件'")
    private String paymentTerms;

    /** 备注 */
    @Length(max = 255, message = "备注不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '备注'")
    private String remark;

    /** 付款状况 */
    @Column(nullable = true)
    private Boolean paymentStatus = false;

    //    /** 关联供应商 */
    //    @ManyToOne
    //    private Manufacturer manufacturer;

    //供应商
    @Column(length = 255, nullable = true)
    private String manufacturerName;

    /** 关联合同项 */
    @OneToMany(mappedBy = "contract", cascade = {CascadeType.ALL }, fetch = FetchType.EAGER)
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<ContractItem> items = new ArrayList<>();

    /** 所属 */
    @Length(max = 255, message = "所属不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String belongs;

    /** 发票 */
    @Length(max = 255, message = "发票不能超过{max}位")
    @Column(length = 255, nullable = true)
    private String bill;

    /** 是否到货 */
    @Comment("bit(1) NOT NULL COMMENT '是否到货'")
    private Boolean whetherArrival = false;

    /** 合同类型 */
    @Length(max = 255, message = "合同类型不能超过{max}位")
    @Column(length = 255, nullable = true)
    private String type;

    /**
     * 附件存储，用||分割多个文件；用@@分割fsId和文件name <br />
     * 16109709907255005.png@@报警通知.png||16109709907255001.png@@报警通知2.png
     */
    @Column(length = 2047, nullable = true)
    private String attachment;

    /** 合同金额 */
    @NotNull(message = "合同金额不能为空")
    private Double amount = 0.0D;
}
